package com.emm.thirdapp;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.leagsoft.emm.thirdparty.EMMToolsUtil;

public class AppJumpActivity extends Activity implements View.OnClickListener {

    TextView tv_jumpH5, tv_jumpOtherApp, tv_getH5Arguments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appjump);

        //测试原生应用跳转原生应用传递过来的值
        String test = getIntent().getStringExtra("test");
        Log.e("test", "AppJumpActivity onCreate:" + test);

        tv_jumpH5 = (TextView) findViewById(R.id.tv_jumpH5);
        tv_jumpH5.setOnClickListener(this);
        tv_jumpOtherApp = (TextView) findViewById(R.id.tv_jumpOtherApp);
        tv_jumpOtherApp.setOnClickListener(this);
        tv_getH5Arguments = (TextView) findViewById(R.id.tv_getH5Arguments);
        tv_getH5Arguments.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_jumpH5) {
            EMMToolsUtil.goToEMMH5(AppJumpActivity.this, "com.leagsoft.baidu");
        } else if (id == R.id.tv_jumpOtherApp) {
            //将app.gradle的包名修改为com.emm.thirdapp.test作为另一个应用包用于测试，需要在后台发布该包名APK
            Intent thirdpartAppIntent = new Intent();
            thirdpartAppIntent.setComponent(new ComponentName("com.emm.thirdapp.test", "com.emm.thirdapp.AppJumpActivity"));
            thirdpartAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            thirdpartAppIntent.putExtra("test", "AppJumpActivity 数据收到了啊");
            startActivity(thirdpartAppIntent);
        } else if (id == R.id.tv_getH5Arguments) {
            String arguments = EMMToolsUtil.getArguments(this);
            Log.e("test", "h5跳转到原生应用的传递过来的参数 arguments:" + arguments);
        }
    }
}
